package com.lovo;

import java.io.*;
import java.util.Scanner;

public class HomeWork0718 {
    private Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
        HomeWork0718 hw = new HomeWork0718();
        hw.copy();
//        hw.append();
    }

    public void copy() {
        //读取
        FileReader fr = null;
        //写入
        FileWriter fw = null;
        try {
            fr = new FileReader("d:/test.txt");
            fw = new FileWriter("d:/test1.txt");
            int d = 0;
            while ((d = fr.read()) != -1) {
                fw.write(d);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fr != null) {
                try {
                    fr.close();
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void append() {
        System.out.println("请输入在文件夹中添加的字");
        String iput = scan.next();
        FileWriter fw = null;
        try {
            fw = new FileWriter("d:/test1.txt", true);
            fw.append(iput);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
